package oo

import (
	"errors"
	"strconv"
	"strings"
)

type SubstringV3 struct {
	String
}

func (o *SubstringV3) Ints() ([]int, error) {
	ss := o.split()

	var number Number
	for _, s := range ss {
		if !number.IsInt(s) {
			return nil, errors.New(s + " is not an integer")
		}
	}

	var values []int
	for _, s := range ss {
		values = append(values, o.toInt(s))
	}

	return values, nil
}

func (o *SubstringV3) split() []string {
	return strings.Split(o.value, ",")
}

func (o *SubstringV3) toInt(s string) int {
	value, _ := strconv.Atoi(s)
	return value
}
